package com.bestcem.xm.user.handler.excel.read.convert;


import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.converters.ReadConverterContext;
import com.alibaba.excel.converters.WriteConverterContext;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.bestcem.xm.user.enums.UserStatusEnum;

/**
 *  用户状态转换
 *
 * @author Linked <zhijian.lin@idiaoyan.com>
 * @version v1.0
 * @date 2022/3/10 15:24
 */
public class UserStatusConvert implements Converter<Integer> {

    public static final String INACTIVATED = "激活中";
    public static final String ACTIVATED = "已启动";
    public static final String DISABLED = "禁用";

    @Override
    public Class<?> supportJavaTypeKey() {
        return Integer.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    /**
     * 这里读的时候会调用
     *
     * @param context
     * @return
     */
    @Override
    public Integer convertToJavaData(ReadConverterContext<?> context) {
        return null;
    }

    /**
     * 用户状态转换
     *
     * @return
     */
    @Override
    public WriteCellData<String> convertToExcelData(WriteConverterContext<Integer> context) {
        if (context.getValue().equals(UserStatusEnum.ACTIVATED.getStatus())) {
            return new WriteCellData<>(ACTIVATED);
        }
        if (context.getValue().equals(UserStatusEnum.INACTIVATED.getStatus())) {
            return new WriteCellData<>(INACTIVATED);
        }
        return new WriteCellData<>(DISABLED);
    }


}
